<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="8">
        <el-card shadow="hover" class="mgb20">
          <div class="user-info">
            <img
              :src="$store.getters.getUserInfo.avatar"
              class="user-avator"
              alt
            />
            <div class="user-info-cont">
              <div class="user-info-name">
                {{ $store.getters.getUserInfo.username }}
              </div>
              <div>{{ $store.getters.getUserInfo.roles[0] }}</div>
            </div>
          </div>

          <div class="user-info-list">
            <span class="left">电话:</span>
            <span>{{ $store.getters.getUserInfo.phone }}</span>
          </div>
          <div class="user-info-list">
            <span class="left">邮箱:</span>
            <span>{{ $store.getters.getUserInfo.email }}</span>
          </div>
          <div class="user-info-list">
            <span class="left">上次登录时间:</span>
            <span>{{ $store.getters.getUserInfo.lastLogin | formatDate }}</span>
          </div>
        </el-card>
        <el-card shadow="hover">
          <template #header>
            <div class="clearfix">
              <span>语言详情</span>
            </div>
          </template>

          Vue
          <el-progress
            :text-inside="true"
            :stroke-width="26"
            :percentage="59.9"
            color="#42b983"
          ></el-progress>

          Java
          <el-progress
            :text-inside="true"
            :stroke-width="26"
            :percentage="34.5"
            color="#f1e05a"
          ></el-progress
          >JavaScript
          <el-progress
            :text-inside="true"
            :stroke-width="26"
            :percentage="3.8"
          ></el-progress
          >HTML 、CSS
          <el-progress
            :text-inside="true"
            :stroke-width="26"
            :percentage="1.8"
            color="#f56c6c"
          ></el-progress>
        </el-card>
      </el-col>
      <el-col :span="16">
        <el-row :gutter="20" class="mgb20">
          <el-col :span="8">
            <el-card shadow="hover" :body-style="{ padding: '0px' }">
              <div class="grid-content grid-con-1">
                <i class="el-icon-user-solid grid-con-icon"></i>
                <div class="grid-cont-right">
                  <div class="grid-num">{{ userTotal }}</div>
                  <div>用户总量</div>
                </div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="8">
            <el-card shadow="hover" :body-style="{ padding: '0px' }">
              <div class="grid-content grid-con-2">
                <i class="el-icon-tickets grid-con-icon"></i>
                <div class="grid-cont-right">
                  <div class="grid-num">{{ messageTotal }}</div>
                  <div>留言总量</div>
                </div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="8">
            <el-card shadow="hover" :body-style="{ padding: '0px' }">
              <div class="grid-content grid-con-3">
                <i class="el-icon-s-data grid-con-icon"></i>
                <div class="grid-cont-right">
                  <div class="grid-num">{{ questionTotal }}</div>
                  <div>党史题数</div>
                </div>
              </div>
            </el-card>
          </el-col>
        </el-row>
        <el-card shadow="hover" style="min-height:403px;">
          <template #header>
            <div class="clearfix">
              <span>项目技术要点</span>
            </div>
          </template>

          <el-table :show-header="false" :data="todoList" style="width:100%;">
            <el-table-column prop="title">
              <template slot-scope="scope">
                <div>
                  <span> {{ scope.row.title }} </span>
                  <span style="display: inline-block; margin-left:30px;">
                    {{ scope.row.desc }}</span
                  >
                </div>
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: "dashboard",
  data() {
    return {
      userTotal: 2132,
      messageTotal: 1512,
      questionTotal: 451,
      todoList: [
        {
          title: "后端框架：Springboot",
          desc: "主流的Java后端开发框架",
        },
        {
          title: "安全框架：Spring Security",
          desc: "解决密码加密",
        },
        {
          title: "测试和日志：Junit、Log4j",
          desc: "记录测试和日志",
        },
        {
          title: "前端：Vue 全家桶",
          desc: "主流的前端开发框架",
        },
        {
          title: "移动端适配：Boostrape",
          desc: "解决不同屏幕尺寸适配问题",
        },
        {
          title: "后台框架：vue-manage-system、 Element UI ",
          desc: "vue-manage-system的开源框架改造",
        },
        {
          title: "数据分析：Echart",
          desc: "开源免费的图表库",
        },
        {
          title: "数据存储：Mysql数据库、Redis缓存",
          desc: "解决数据存储、频繁发送请求",
        },
        {
          title: "连接池：Druid",
          desc: "阿里开源的数据库连接池，mysql优化",
        },
      ],
    };
  },

  filters: {
    // 发表时间格式化
    formatDate(val) {
      return new Date(val).toLocaleString();
    },
  },
  created() {
    this.getCount();
  },

  methods: {
    async getCount() {
      const userTotal = await this.$http.get("/admin/countUser");
      const messageTotal = await this.$http.get("/admin/countMessage");
      const questionTotal = await this.$http.get("/admin/countQuestion");

      if (
        userTotal.code == 200 &&
        messageTotal.code == 200 &&
        questionTotal.code == 200
      ) {
        this.userTotal = userTotal.data;
        this.messageTotal = messageTotal.data;
        this.questionTotal = questionTotal.data;
      }
      console.log(userTotal);
    },
  },
};
</script>

<style scoped>
.el-row {
  margin-bottom: 20px;
}
.el-card {
  padding: 10px;
}

.grid-content {
  display: flex;
  align-items: center;
  height: 100px;
}

.grid-cont-right {
  flex: 1;
  text-align: center;
  font-size: 14px;
  color: #999;
}

.grid-num {
  font-size: 30px;
  font-weight: bold;
}

.grid-con-icon {
  font-size: 50px;
  width: 100px;
  height: 100px;
  text-align: center;
  line-height: 100px;
  color: #fff;
}

.grid-con-1 .grid-con-icon {
  background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
  color: rgb(45, 140, 240);
}

.grid-con-2 .grid-con-icon {
  background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
  color: rgb(45, 140, 240);
}

.grid-con-3 .grid-con-icon {
  background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
  color: rgb(242, 94, 67);
}

.user-info {
  display: flex;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 2px solid #ccc;
  margin-bottom: 20px;
}

.user-avator {
  width: 120px;
  height: 120px;
  border-radius: 50%;
}

.user-info-cont {
  padding-left: 50px;
  flex: 1;
  font-size: 14px;
  color: #999;
}

.user-info-cont div:first-child {
  font-size: 30px;
  color: #222;
}

.user-info-list {
  font-size: 14px;
  color: #999;
  line-height: 25px;
  display: flex;
}
.user-info-list .left {
  display: inline-block;
  width: 6.125rem;
  margin: 0 10px;
}

.user-info-list span {
  margin-left: 5px;
}

.mgb20 {
  margin-bottom: 20px;
}

.todo-item {
  font-size: 14px;
}

.todo-item-del {
  text-decoration: line-through;
  color: #999;
}

.schart {
  width: 100%;
  height: 300px;
}
</style>
